package cn.pconline.autoclub.task;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

import org.apache.log4j.PropertyConfigurator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author zhouruxuan
 * @date 2015年1月15日 上午9:34:01
 * 
 * 定时任务入口工具类
 * 1.初始化定时任务日志记录，供定时入口的Main方法调用
 * 
 */
public class AppUtils {

	public static Logger log = null;

	public static <T> void initLog(Class<T> type) {
        FileInputStream istream = null;
        try {
            Properties props = new Properties();
            istream = new FileInputStream(FileUtils.confDir + File.separator + FileUtils.log4jName);
            props.load(istream);
            istream.close();
            String logFile = props.getProperty("log4j.appender.autoclubtask.File");//设置路径
            props.setProperty("log4j.appender.logfile.File", new File(logFile).getAbsolutePath());
            PropertyConfigurator.configure(props);//装入log4j配置信息
            log  = LoggerFactory.getLogger(type);
            ClubMemberPetrolTask.setLog(LoggerFactory.getLogger(ClubMemberPetrolTask.class));
            ClubPetrolTask.setLog(LoggerFactory.getLogger(ClubPetrolTask.class));
        } catch (FileNotFoundException ex) {
            System.out.println("need config file:" + FileUtils.confDir + File.separator + FileUtils.log4jName);
            log .error("initLog fail--FileNotFoundException!", ex);
        } catch (IOException ex) {
            log .error("initLog fail--IOException!", ex);
        } finally {
            try {
                istream.close();
            } catch (IOException ex) {
                log .error("initLog fail, when close inputStream!", ex);
            }
        }
    }
}
